package com.opennetexam.manager.sqlprovider;

import org.apache.log4j.Logger;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 奶茶
 * Created on 2017/11/8.
 */
public class AdminLoginLogProvider {

    private static Logger logger = Logger.getLogger(AdminLoginLogProvider.class);

    public String findAdminLoginLogBySomeWhere(Map<String,Object> parameter){
        StringBuilder stringBuffer = new StringBuilder("SELECT * FROM AdminLoginLog WHERE 1=1");
        if(parameter.get("examSiteId") != null){
            stringBuffer.append(" AND ExamSiteID = \'").append(parameter.get("examSiteId")).append("%\' ");
        }
        if(parameter.get("loginIp") != null && !("").equals(parameter.get("loginIp"))){
            stringBuffer.append(" AND LoginIPAddress LIKE \'%").append(parameter.get("loginIp")).append("%\'");
        }
        if(parameter.get("loginStatus") != null && !("").equals(parameter.get("loginStatus"))){
            stringBuffer.append(" AND LoginStatus LIKE \'%").append(parameter.get("loginStatus")).append("%\'");
        }
        if(parameter.get("beginTime") != null  && !("").equals(parameter.get("beginTime"))){
            stringBuffer.append(" AND LoginTime >= \'").append(parameter.get("beginTime")).append("\'");
        }
        if(parameter.get("endTime") != null && !("").equals(parameter.get("endTime"))){
            stringBuffer.append(" AND LoginTime <= \'").append(parameter.get("endTime")).append("\'");
        }
        logger.info(stringBuffer.toString());
        return stringBuffer.toString();
    }

    public static void main(String[] args){
        Map<String,Object> map = new HashMap<>();
        map.put("examSiteId",123);
        map.put("loginIp","123");
        map.put("loginStatus","123");
        map.put("beginTime","123");
        map.put("beginTime","123");

//        String adminLoginLogBySomeWhere = findAdminLoginLogBySomeWhere(map);
//        System.out.println(adminLoginLogBySomeWhere);

    }
}
